import recom from '@/components/regionComponent.vue'
import ctime from '@/components/changeTime.vue'
export default {
  components: {
    recom,
    ctime,
  },
  data() {
    return {
      outsideimgwg: [], //外饰图片暂存，页面显示
      fmShopname: '', //店铺名称-页面渲染显示
      Seriesid: '', //系列id
      showys: false, //外观/内饰 颜色弹框
      wgColorList: [], //选择配置后,通过选择配置带出外观颜色list
      nsColorList: [], //选择配置后,通过选择配置带出内试颜色list
      xedColorList: [], //选择后的外观颜色list
      xzwgcolor: {
        OuterColour: {},
        InColour: {},
      }, //选择外观颜色
      colortype: true, //未选择颜色,出现的问题提示
      fanhuiimg: '', //相册上传图片后 返回的图片
      //表示所有颜色色全
      Sequanwg: {
        ColorCoding: 'linear-gradient(0deg,rgba(255,49,49,1),rgba(255,243,52,1),rgba(37,191,255,1))',
        Color: '色全',
      },
      Sequanns: {
        neiColor: [
          'linear-gradient(0deg,rgba(255,49,49,1),rgba(255,243,52,1),rgba(37,191,255,1))',
        ],
        Color: '色全',
        ColorCoding: 'linear-gradient(0deg,rgba(255,49,49,1),rgba(255,243,52,1),rgba(37,191,255,1))',
      },
      bussvalidPeriod: '2029-1-1', //商户有效期
      // 商户端有效期
      showcq: false,
      validPeriod: '请选择', //有效期请选择
      modecq: 'time',
      paramscq: {
        year: true,
        month: true,
        day: true,
      },
      clcivalidPeriod: '2029-1-1', //客户有效期
      currentTime: new Date().toISOString().slice(0, 10),
      // 客户端有效期
      showcqkh: false,
      validPeriodKH: '请选择', //有效期请选择
      khparamscq: {
        year: true,
        month: true,
        day: true,
      },
      //生产时间
      showscrq: false,
      Production: new Date().toISOString().slice(0, 10),
      // Production: '',
      modesc: 'time',
      paramssc: {
        year: true,
        month: true,
        day: true,
      },
      showhg: false, //选择合格证
      hgtitlet: '', //合格证title
      showxq: false, //车辆详情
      xqtitlet: '', //车辆详情title
      showdz: false, //车辆所在地
      paramsdz: {
        province: true,
        city: true,
      },
      vehicleLocation: 0, //车辆所在地id
      vehicleAddrName: '', //车辆所在地name
      showzt: false, //车辆状态
      zttitlet: '', //状态title
      showqy: false, //车辆销售区域
      paramsqy: {
        //车辆销售区域
        province: true,
        city: true,
      },
      salesAreaId: 0, //销售区域id
      salesAreaName: '', //销售区域name

      showimg: false, //图片选择.官方,平台,相册,相机
      imgdid: 0, //(1,外观图上传 2,内饰图上传  3,详情图上传)

      gfdimgwg: [],
      ptscid: 0, //平台素材ID

      ALLlistgs: {
        type: 2, //商品类型，0商户端，1客户端，2同时发布 ,
        car: {},
        Color: [],
        img: {},
      },
      show: false,
      content: '您已成功发布新车！点击 ',
      contentxq: '查看详情>>',
      goodsidcar: '', //返回车子id
      historyList: '', //品牌历史记录
      specifAll: {
        Speciflist: [], //规格
        brandlist: [], //品牌
        Serieslist: [], //系列
        Configulist: [], //车子
        addrestype: [], //上牌地址
        Areaaddress: [], //区域地址
      },
      Whethertosubmit: '1', //是否提交车源--编辑车源
      showxj: false, //删除车源
      checked0: false, //选择商家端
      checked1: false, //选择客户端
      current: 0, // tabs组件的current值，表示当前活动的tab选项
      swiperCurrent: 0, // swiper组件的current值，表示当前那个swiper-item是活动的
      // tabs切换
      titleTabs: [{
        name: '面向商家端',
        checked: false,
      },
      {
        name: '面向消费端',
        checked: false,
      },
      ],
      dataALLlistgs: {
        MyProperty: this.selecPort, //商品类型（0商户端，1客户端，2商户端客户端）
        GoodsDetails: {
          Store_Id: '', //店铺id
          Valid_Time: '2029-1-1', //车源有效时间（长期为2999年1月1日）
          Factory_Price: '', //官方指导价
          Bus_Price: '', //客户端渠道销售价格
          Client_price: '', //客户端裸车价
          Is_loans: '', //全款/按揭（0关，1开（开了后没有低首付和以租代售））
          Down_Payment_Id: '', //低首付金融方案id
          Down_Payment_Money: '', //低首付保证金s暂存
          Rent_Out_Id: '', //以租代售金融方案id
          Rent_Out_Money: '', //以租代售保证金s暂存
          Specification: '', //规格（0国产，1美规，2中东，3加版，4欧版，5墨西哥版）
          Brand_Id: '', //品牌id
          Brand_Name: '', //品牌名称
          Car_Type_Id: '', //车辆型号id
          Car_Type_Nmae: '', //车辆型号名称
          Configuration_Id: '', //车子配置id
          Configuration_Name: '', //车子配置名称
          Inventory: '', //库存数量
          Earnest_Money: '', //保证金
          Produced_Date: null, //生产日期
          Conformity_Certificate: '', //车辆合格证（0随车，1邮寄）
          Cardetail_Type: '', //车辆情况 0现车现票/不店保，1现车现票/店保，2质损车源，3期货/店保，4其他
          Car_Status: '', //车辆状态（0现货，1在途）
          Car_Location_Id: '', //车俩所在地id(为最小地区id)
          Car_Location_Name: '', //车辆所在地区名称
          Sales_Territory_Id: '', //销售区域id(为最小地区id)
          Sales_Territory_Name: '', //销售区域名称
          Bus_Remarks: '', //商户端备注
        },
        ColourList: this.xedColorList,
        ImgList: this.outsideimgwg,
      },
      fullAmount: false, //全款/按揭
      lowDownPayment: false, //低首付
      rentForSale: false, //以租代售

      swipHeight: '1480rpx', //swiper高度调节
      reason: '', //备注
      reginnumber: null, //备注的字数
      carImageS: [], //选择后的图片地址list
      currentimgList: [], //选择后的图片list
      selecPort: 0, //选择端口商品类型（0商户端，1客户端，2商户端客户端）
      bussGuidePrice: 0, //官方指导价商户端
      clickGuidePrice: 0, //官方指导价客户端
      bareCarPrice: 0, //裸车价客户端
      isLoans: 0, //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      inStockS: 0, //库存
      bussMargin: 0, //商户端保证金
      vehicleCertificate: null, //车辆合格证
      vehicleDetails: null, //车辆详情
      vehicleStatus: null, //车辆状态

      // 上传图片
      imgPolicy: '',
      imgAuthorization: '',
      imgHost: '',

      faceimg: '', //返回图片地址
      // 低首付
      financialSolution: {
        fsid: '',
        fsname: '低首付',
      },
      //以租代售
      yzdsclicklist: {
        yzdsid: '',
        yzdsname: '以租代售',
      },

      // 编辑车源
      goodsid: '', //编辑车源id
      goodsList: '', //返回-编辑车源list
      goodsXiajia: '', //编辑车源是否下架

      showXiajia: false, //下架
      //上架日期
      showsjrqS: false,
      validPeriodS: '', //有效期请选择
      ProductionS: new Date().toISOString().slice(0, 10),
      modescS: 'time',
      paramsscS: {
        year: true,
        month: true,
        day: true,
      },
      changqili: [{
        name: '长期有效',
        check: false,
        vlue: '2029-1-1',
      },
      {
        name: '自定义时间',
        check: true,
      },
      ],
      subfalse: false //点击确定按钮
    }
  },
  onLoad(busslist) {
    this.fmShopname = this.$store.state.userInfoDetail.store.storeName //店铺名称

    // 选择规格，品牌，系列，车子，地址
    uni.$on('specifAll', data => {
      Object.assign(this.specifAll, data)
      this.Seriesid = this.specifAll.Serieslist.carTypeId //车型系列id
      //this.specifAll.Configulist.Id //车子id
      if (this.specifAll.Configulist.id !== undefined) {
        this.GetCarColourDataList() // —默认图5张
      }
    })

    // 选择后的图片
    uni.$on('carSourceColor', data => {
      console.log('车源颜色' + this.xedColorList)
      Object.assign(this.xedColorList, data)
      this.xedColorList = data.colors
      console.log('23423：', data.colors)
      console.log('车源返回：', this.xedColorList)
    })
    // 单选选择后的图片地址list
    uni.$on('carImageS', data => {
      Object.assign(this.carImageS, data)
      this.carImageS = data.carImageS
      this.outsideimgwg = this.carImageS
    })
    // 多选选择后的图片地址list
    uni.$on('currentimgList', data => {
      Object.assign(this.currentimgList, data)
      this.currentimgList = data.currentimgList
      this.outsideimgwg = this.outsideimgwg.concat(this.currentimgList)
    })
    // 低首付金融方案id
    uni.$on('financialSolution', data => {
      this.financialSolution = {
        fsid: 0,
        fsname: '低首付',
      }
      Object.assign(this.financialSolution, data)
    })
    // 以租代售金融方案id
    uni.$on('yzdsclicklist', data => {
      this.yzdsclicklist = {
        yzdsid: 0,
        yzdsname: '',
      }
      Object.assign(this.yzdsclicklist, data)
    })

    //1:发布车源   110：编辑删除车源
    if (busslist.type === '1') {
      uni.setNavigationBarTitle({
        title: '发布车源',
      })
    } else if (busslist.type === '110') {
      this.Whethertosubmit = busslist.type
      this.goodsid = busslist.goodsid //车子id
      this.goodsXiajia = Number(busslist.sheelistid) //上下架状态(0上架,1下架)
      this.GetUpdateCarSourceDataDataList()
      uni.setNavigationBarTitle({
        title: '编辑车源',
      })
    }
  },
  // vue实例加载完成
  created() {},
  mounted() {
    this.getImageConfig()
    // this.GetStoreDataList()
  },
  methods: {
    //  编辑车源-渲染数据
    async GetUpdateCarSourceDataDataList() {
      try {
        let data = {
          PageIndex: 1, //当前页码
          PageSize: 10, //每页条数
          Id: this.goodsid, //车源商品id
        }
        const res = await this.$api.carSource.GetUpdateCarSourceDataDataList(
          data
        )
        this.goodsList = res.data.list[0]
        console.log(res.data.list[0])
        this.fmShopname = this.goodsList.store_Name //店铺名称
        //品牌.系列.配置
        var spername = ''
        if (this.goodsList.specification === 0) {
          spername = '国产'
        } else if (this.goodsList.specification === 1) {
          spername = '美规'
        } else if (this.goodsList.specification === 2) {
          spername = '中东'
        } else if (this.goodsList.specification === 3) {
          spername = '加版'
        } else if (this.goodsList.specification === 4) {
          spername = '欧版'
        } else if (this.goodsList.specification === 5) {
          spername = '墨西哥版'
        }
        this.specifAll = {
          Speciflist: {
            name: spername,
            id: this.goodsList.specification,
          },
          brandlist: {
            bid: this.goodsList.brand_Id,
            brand: this.goodsList.brand_Name,
          },
          Serieslist: {
            carTypeId: this.goodsList.car_Type_Id,
            carTypeName: this.goodsList.car_Type_Name,
          },
          Configulist: {
            id: this.goodsList.configuration_Id,
            name: this.goodsList.configuration_Name,
            factoryprice: this.goodsList.factory_Price
          },
        }
        this.colortype = true
        this.xedColorList = this.filtercolor(this.goodsList.colourList) //颜色

        this.outsideimgwg = this.goodsList.imgList //图片

        //判断长期时间还是选择的时间
        if (this.goodsList.valid_Time === '2029-01-01T00:00:00Z') {
          this.bussvalidPeriod = this.goodsList.valid_Time //有效期
        } else {
          this.validPeriod = this.goodsList.valid_Time
        }
        this.dataALLlistgs.GoodsDetails.Inventory = this.goodsList.inventory //库存

        this.reason = this.goodsList.bus_Remarks //备注

        this.Seriesid = this.goodsList.car_Type_Id //系列id

        this.dataALLlistgs.GoodsDetails.Down_Payment_Money = this.goodsList.down_Payment_Money //低首付保证金
        this.dataALLlistgs.GoodsDetails.Rent_Out_Money = this.goodsList.rent_Out_Money //以租代售保证金

        //判断面向商户端还是客户端（0商户端，1客户端，2商客端）
        if (this.goodsList.goods_Type === 0) {
          //商客端
          this.checked0 = true
          this.selecPort = 0
          this.swiperCurrent = 0
          this.bussiness()
        } else if (this.goodsList.goods_Type === 1) {
          //客户端
          this.checked1 = true
          this.selecPort = 1
          this.swiperCurrent = 1
          this.client()
        } else {
          this.checked0 = true
          this.checked1 = true
          this.selecPort = 2
          this.bussiness()
          this.client()
        }

      } catch (err) {
        console.log(err)
      }
    },
    // 发布至商户端字段加载
    bussiness() {
      if (this.vehicleCertificate === 0) {
        this.hgtitlet = '随车'
      } else {
        this.hgtitlet = '邮寄'
      }
      // this.specifAll.Configulist.factoryprice = this.goodsList.factory_Price //官方指导价
      this.dataALLlistgs.GoodsDetails.Bus_Price = this.goodsList.bus_Price //渠道销售价
      this.dataALLlistgs.GoodsDetails.Earnest_Money = this.goodsList.earnest_Money //保证金
      this.vehicleAddrName = this.goodsList.car_Location_Name //车辆所在地
      this.salesAreaName = this.goodsList.sales_Territory_Name //销售区域
      this.Production = this.goodsList.produced_Date.split(' ')[0] //生产日期
      this.vehicleDetails = this.goodsList.cardetail_Type //车辆详情id
      this.vehicleCertificate = this.goodsList.conformity_Certificate //合格证id
      if (this.vehicleDetails === 4) {
        this.xqtitlet = '其他'
      } else if (this.vehicleDetails === 0) {
        this.xqtitlet = '现车现票/不店保'
      } else if (this.vehicleDetails === 1) {
        this.xqtitlet = '现车现票/店保'
      } else if (this.vehicleDetails === 2) {
        this.xqtitlet = '质损车源'
      } else if (this.vehicleDetails === 3) {
        this.xqtitlet = '期货/店保'
      }

      this.vehicleStatus = this.goodsList.car_Status //车辆状态
      if (this.vehicleStatus === 0) {
        this.zttitlet = '现货'
      } else {
        this.zttitlet = '在途'
      }
    },
    // 发布至客户端字段加载
    client() {
      // this.specifAll.Configulist.factoryprice = this.goodsList.factory_Price //官方指导价
      this.dataALLlistgs.GoodsDetails.Client_price = this.goodsList.client_Price //客户端裸车价

      this.isLoans = this.goodsList.is_Loans //全款/按揭（0false关，1true开
      if (this.isLoans === 0) {
        this.lowDownPayment = false
        this.rentForSale = false
        this.fullAmount = false //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      } else {
        this.fullAmount = true //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      }
      this.financialSolution.name = this.goodsList.down_Payment_Name //低首付名称
      this.yzdsclicklist.name = this.goodsList.rent_Out_Name //以租代售名称
      this.financialSolution.fsid = this.goodsList.down_Payment_Id //低首付id
      this.yzdsclicklist.yzdsid = this.goodsList.rent_Out_Id //以租代售id
      if (this.financialSolution.fsid === '') {
        //低首付选中
        this.lowDownPayment = false
      } else {
        this.lowDownPayment = true
      }
      if (this.yzdsclicklist.yzdsid === '') {
        //以租代售选中
        this.rentForSale = false
      } else {
        this.rentForSale = true
      }
    },
    //分割颜色
    filtercolor(data) {
      data.forEach(item => {
        var arr = item.inColour.colorCoding.split('/')
        item.inColour.neiColor = arr
      })
      return data
    },

    // 选择配置后—默认图5张
    async GetCarColourDataList() {
      try {
        let data = {
          CarTypeId: this.Seriesid, //系列id
        }
        const res = await this.$api.carSource.GetCarColourDataList(data)
        this.outsideimgwg = res.data.list[0].carImg
      } catch (err) {
        console.log(err)
      }
    },
    // 店铺
    async GetStoreDataList() {
      try {
        let data = {
          PageIndex: 1, //当前页码
          PageSize: 10, //每页条数
          CarTypeId: this.$store.state.userInfoDetail.store.storeId, //系列id
        }
        const res = await this.$api.carSource.GetStoreDataList(data)
      } catch (err) {
        console.log(err)
      }
    },
    //规格-赋值3
    guigexz() {
      //跳转规格
      uni.navigateTo({
        url: '/pages_common/chooseSpecifications/chooseSpecifications?type=110',
      })
      //重新点击规格,清空下面参数
      this.xedColorList = []
      this.colortype = true
    },
    //选择商户端和客户端
    checkedClick(type) {
      //selecPort选择端口商品类型（0商户端，1客户端，2商户端客户端）
      if (this.checked0 === true && this.checked1 === true) {
        this.selecPort = 2
      } else if (this.checked0 === true) {
        this.selecPort = 0
      } else {
        this.selecPort = 1
      }
    },
    //选择客户端和商户端
    chec2Click(type) {
      if (this.checked1 === true && this.checked0 === true) {
        this.selecPort = 2
      } else if (this.checked1 === true) {
        this.selecPort = 1
      } else {
        this.selecPort = 0
      }
    },
    //根据时间跳到不同的事件区域
    bindChange: function(index) {
      const val = index.detail.value
      var id = '#floor_2020'
      uni
        .createSelectorQuery()
        .select('.bjcolor')
        .boundingClientRect(data => {
          //目标节点
          uni
            .createSelectorQuery()
            .select(id)
            .boundingClientRect(res => {
              //最外层盒子节点
              uni.pageScrollTo({
                duration: 500, //过渡时间必须为0，uniapp bug，否则运行到手机会报错
                scrollTop: res.top - 150, //滚动到实际距离是元素距离顶部的距离
              })
            })
            .exec()
        })
        .exec()
    },
    //选择配置，可以打开颜色弹框
    xzcolorlick() {
      if (this.specifAll.Configulist.length === 0) {
        setTimeout(function() {
          uni.showToast({
            title: '请先选择配置',
            duration: 2000,
            icon: 'none',
          })
        }, 100)
        return false
      } else {
        // 颜色列表
        uni.navigateTo({
          url: '/pages_common/exteriorInterior/exteriorInterior?colorList=' +
            encodeURIComponent(JSON.stringify(this.specifAll.Configulist)) +
            '&type=1110' +
            '&xedColorLists=' +
            encodeURIComponent(JSON.stringify(this.xedColorList)),
        })
      }
    },
    //商户端有效期
    validPeriodClick(e) {
      this.validPeriod = ''
      if (this.modecq === 'time') {
        if (this.paramscq.year) this.validPeriod += e.year
        if (this.paramscq.month) this.validPeriod += '-' + e.month
        if (this.paramscq.day) this.validPeriod += '-' + e.day
        if (this.paramscq.hour) this.validPeriod += ' ' + e.day
        if (this.paramscq.minute) this.validPeriod += ':' + e.minute
        if (this.paramscq.second) this.validPeriod += ':' + e.second
      } else {
        this.validPeriod = e.year + '-' + e.month + '-' + e.day
      }
      this.bussvalidPeriod = this.validPeriod

      var riqi1 = Number(this.validPeriod.match(/\d+/g).join('')) //选择的日期
      var riqi2 = Number(this.currentTime.match(/\d+/g).join('')) //今天
      // 车源有效期需大于当前日期
      if (riqi1 < riqi2) {
        this.$refs.uToast.show({
          title: '车源有效期需大于当前日期',
          type: 'warning',
          url: '/pages/user/index',
        })
        this.validPeriod = '请选择'
      } else {
        this.showcq = false
      }
    },
    //客户端有效期
    kuValidPeriodClick(e) {
      this.validPeriodKH = ''
      if (this.modecq === 'time') {
        if (this.khparamscq.year) this.validPeriodKH += e.year
        if (this.khparamscq.month) this.validPeriodKH += '-' + e.month
        if (this.khparamscq.day) this.validPeriodKH += '-' + e.day
        if (this.khparamscq.hour) this.validPeriodKH += ' ' + e.day
        if (this.khparamscq.minute) this.validPeriodKH += ':' + e.minute
        if (this.khparamscq.second) this.validPeriodKH += ':' + e.second
      } else {
        this.validPeriodKH = e.year + '-' + e.month + '-' + e.day
      }
      this.clcivalidPeriod = this.validPeriodKH
      this.showcqkh = false
    },

    //生产时间
    confirmsc(e) {
      this.Production = ''
      if (this.modesc === 'time') {
        if (this.paramssc.year) this.Production += e.year
        if (this.paramssc.month) this.Production += '-' + e.month
        if (this.paramssc.day) this.Production += '-' + e.day
        if (this.paramssc.hour) this.Production += ' ' + e.day
        if (this.paramssc.minute) this.Production += ':' + e.minute
        if (this.paramssc.second) this.Production += ':' + e.second
      } else {
        this.Production = e.year + '-' + e.month + '-' + e.day
      }
      this.showscrq = false
    },
    //商户端有效期关闭
    closevalidPeriod() {
      this.showcq = false
    },
    //客户端有效期关闭
    KHclosevalidPeriod() {
      this.showcqkh = false
    },
    //生产时间关闭
    closeTime() {
      this.showscrq = false
    },
    close() {
      this.showdz = false
    },
    //合格证
    hgclick(type) {
      this.showhg = false
      if (type === 0) {
        this.hgtitlet = '随车'
      } else {
        this.hgtitlet = '邮寄'
      }
      this.vehicleCertificate = type
    },
    //车辆详情
    xqclick(type) {
      this.showxq = false
      if (type === 4) {
        this.xqtitlet = '其他'
      } else if (type === 0) {
        this.xqtitlet = '现车现票/不店保'
      } else if (type === 1) {
        this.xqtitlet = '现车现票/店保'
      } else if (type === 2) {
        this.xqtitlet = '质损车源'
      } else if (type === 3) {
        this.xqtitlet = '期货/店保'
      }
      this.vehicleDetails = type
    },

    //车辆所在地
    confirmdz(e) {
      this.vehicleLocation = e.city.id
      this.vehicleAddrName = e.province.label + e.city.label
      this.showdz = false
    },
    //车辆状态
    ztclick(type) {
      this.showzt = false
      if (type === 0) {
        this.zttitlet = '现货'
      } else {
        this.zttitlet = '在途'
      }
      this.vehicleStatus = type
    },
    //销售区域---单选一个地区
    confirmqy(e) {
      this.salesAreaId = e.city.id
      this.salesAreaName = e.province.label + e.city.label
    },
    allqgclick() {
      this.showqy = false
      this.salesAreaName = '全国'
    },
    //删除颜色
    tagClick(e, index) {
      this.xedColorList.splice(index, 1) //取消
      if (
        this.xedColorList === '' ||
        this.xedColorList === undefined ||
        this.xedColorList.length === 0
      ) {
        this.colortype = true
      }
    },
    // 选择上传图片方式,,存储是哪一个类型图片(1,外观,2,内饰,3,详情)
    UploadIDcardImgtk(e) {
      this.imgdid = e //存储
      this.showimg = true //打开上传图片弹框
    },
    //选择图片上传方式--官方图
    UploadimgGF(typeid) {
      this.ptscid = typeid
      if (this.specifAll.Configulist.length === 0) {
        setTimeout(function() {
          uni.showToast({
            title: '请先选择配置',
            duration: 2000,
            icon: 'none',
          })
        }, 100)
        return false
      }
      let imgsum = this.outsideimgwg.length
      uni.navigateTo({
        url: '/pages_carSource/appearancePicture/appearancePicture?Seriesid=' +
          this.Seriesid +
          '&&type=' +
          typeid +
          '&&panduan=110' +
          '&&imgsum=' +
          imgsum,
      })
      this.showimg = false
    },
    //选择图片上传方式--平台图片
    UploadimgPT(typeid) {
      this.ptscid = typeid
      if (
        this.Seriesid === 0 ||
        this.Seriesid === '' ||
        this.Seriesid === undefined
      ) {
        setTimeout(function() {
          uni.showToast({
            title: '请先选择配置',
            duration: 2000,
            icon: 'none',
          })
        }, 100)
        return false
      }
      let imgsum = this.outsideimgwg.length
      uni.navigateTo({
        url: '/pages_carSource/appearancePicture/appearancePicture?Seriesid=' +
          this.Seriesid +
          '&&type=' +
          typeid +
          '&&panduan=110' +
          '&&imgsum=' +
          imgsum,
      })
      this.showimg = false
    },

    //选择图片上传方式--拍摄
    UploadIDcardpaishe(type) {
      this.showimg = false
      if (
        this.Seriesid === 0 ||
        this.Seriesid === '' ||
        this.Seriesid === undefined
      ) {
        setTimeout(function() {
          uni.showToast({
            title: '请先选择配置',
            duration: 2000,
            icon: 'none',
          })
        }, 100)
        return false
      }
      this.uploadImage(type)
    },
    //选择图片上传方式--相册
    UploadIDcardImg(type) {
      this.showimg = false
      if (
        this.Seriesid === 0 ||
        this.Seriesid === '' ||
        this.Seriesid === undefined
      ) {
        setTimeout(function() {
          uni.showToast({
            title: '请先选择配置',
            duration: 2000,
            icon: 'none',
          })
        }, 100)
        return false
      }
      this.uploadImage(type)
    },
    //获取图片上传配置信息
    async getImageConfig() {
      try {
        const res = await this.$api.user.getImageConfig()
        this.imgAuthorization = res.data.auth
        this.imgPolicy = res.data.policy
        this.imgHost = res.data.host
      } catch (e) {
        //TODO handle the exception
      }
    },
    //选择图片
    uploadImage(type) {
      // const _this = this
      uni.chooseImage({
        count: 1,
        sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
        success: result => {
          uni.showLoading({
            title: '图片上传中~',
          })
          //请求接口获取上传文件的参数
          this.$api.files
            .uploadImg({
              filePath: result.tempFilePaths[0],
            })
            .then(res => {
              console.log(res)
              var abc = res.baseUrl + res.url
              this.FanHUIimgs(abc)
              uni.hideLoading()
            })
          // uni.request({
          //   url: 'https://testapi.yzsheng.com/bussiness/Common/UploadReceiptImgUpyunConfig',
          //   method: 'POST',
          //   data: {
          //     policy: _this.imgPolicy,
          //     authorization: _this.imgAuthorization,
          //     fname: Math.random() * 10,
          //     sFile: result.tempFilePaths[0], // 图片流
          //   },
          //   success: ConfigResult => {
          //     var UPYUN = ConfigResult
          //     var yunUrl = UPYUN['data'].host
          //     //上传文件
          //     uni.uploadFile({
          //       url: yunUrl,
          //       // files: result.tempFiles,
          //       formData: {
          //         policy: UPYUN['data'].policy,
          //         authorization: UPYUN['data'].auth
          //       },
          //       filePath: result.tempFilePaths[0],
          //       name: 'file',
          //       success(res) {
          //         if (JSON.parse(res.data).code === 200) {
          //           var abc = 'https://ztc.yzsheng.com/' + JSON.parse(res.data).url
          //           _this.FanHUIimgs(abc)
          //         }
          //         uni.hideLoading()
          //       },
          //       fail(er) {}
          //     })
          //     uni.hideLoading()
          //   }
          // })
        },
        error: function(e) {},
      })
    },
    //上传图片赋值
    FanHUIimgs(res) {
      var wgimg = {
        img: res,
      }
      this.outsideimgwg.push(wgimg)
    },

    // 监听swiper
    swiperChange(e) {
      this.bannerswiperCurrent = e.detail.current
    },

    // 切换订单tab
    tabsChange(index) {
      this.swiperCurrent = index
    },

    // swiper-item左右移动，通知tabs的滑块跟随移动
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },

    // 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
    // swiper滑动结束，分别设置tabs和swiper的状态
    animationfinish(e) {
      let current = e.detail.current
      this.$refs.uTabs.setFinishCurrent(current)
      this.swiperCurrent = current
      this.current = current
      if (this.current === 0) {
        this.swipHeight = '1480rpx'
        // 如果备注字数超过则扩大swiper
        if (this.reginnumber > 336) {
          this.swipHeight = '2200rpx'
        } else if (this.reginnumber > 231) {
          this.swipHeight = '2000rpx'
        } else if (this.reginnumber > 126) {
          this.swipHeight = '1800rpx'
        } else if (this.reginnumber > 63) {
          this.swipHeight = '1600rpx'
        }
      } else {
        if (this.rentForSale && this.lowDownPayment) {
          this.swipHeight = '1250rpx'
        } else if (this.lowDownPayment) {
          this.swipHeight = '1080rpx'
        } else if (this.rentForSale) {
          this.swipHeight = '1080rpx'
        } else {
          this.swipHeight = '880rpx'
        }
      }
    },
    // switch选择切换
    qiehuan1() {
      this.swiperCurrent = 0
      this.current = 0
    },
    qiehuan2() {
      this.swiperCurrent = 1
      this.current = 1
    }, // 全款按揭
    fullAmountChange: function(e) {
      if (this.fullAmount) {
        this.lowDownPayment = false
        this.rentForSale = false
        this.isLoans = 1 //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      } else {
        this.isLoans = 0 //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      }
    },
    //低首付
    lowDownPChange: function(e) {
      if (this.lowDownPayment) {
        this.fullAmount = false
        this.isLoans = 0 //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      } else {

      }
    },
    //以租代售
    rentForSChange: function(e) {
      if (this.rentForSale) {
        this.fullAmount = false
        this.isLoans = 0 //全款/按揭（0关，1开（开了后没有低首付和以租代售））
      }
    },
    //商户端车源有效期
    valclick() {
      this.validPeriod = '请选择'
      this.bussvalidPeriod = '2029-1-1'
    },
    //客户端车源有效期
    valKhClick() {
      this.validPeriodKH = '请选择'
      this.clcivalidPeriod = '2029-1-1'
    },
    blur(value) {
      this.reginnumber = value.detail.value.length
    },
    // 预览图片多张
    previewImg(index) {
      // 跳转至图片替换/删除页面
      uni.navigateTo({
        url: '/pages_carSource/vehiclePictureSelect/vehiclePictureSelect?outsideimgwg=' +
          encodeURIComponent(JSON.stringify(this.outsideimgwg)) +
          '&&indexs=' +
          index +
          '&&Seriesid=' +
          this.Seriesid,
      })
    },
    //金融方案
    financialPlanClick(index) {
      if (this.dataALLlistgs.GoodsDetails.Client_price === '') {
        uni.showToast({
          title: '请输入裸车价',
          duration: 2000,
          icon: 'none',
        })
        return false
      }
      // 0低首付1金融方案
      uni.navigateTo({
        url: '/pages_carSource/myFinancialPlan/myFinancialPlan?type=' + index + '&moneynum=' + this.dataALLlistgs.GoodsDetails
          .Client_price,
      })
    },
    // 库存
    inventoclick(e) {
      const v = e.detail.value
      this.dataALLlistgs.GoodsDetails.Inventory = '1'

      const zero = /^(0{2,})|[^0-9]/g
      let final = 0
      if (!v) {
        final = 0
      } else {
        final = v.toString().replace(zero, v => {
          return 0
        })

        if (final.split('')[0] * 1 === 0) {
          final = final.slice(1) - 0 || 0
        }
      }
      this.$nextTick(() => {
        this.dataALLlistgs.GoodsDetails.Inventory = final.toString() || '0'
      })
    },
    // 新车发布数据提交
    submitclick() {
      console.log(123)
      // // 0商户端1客户端
      if (!this.checked0 && !this.checked1) {
        uni.showToast({
          title: '请选择商家端/消费端信息',
          duration: 2000,
          icon: 'none',
        })
        return false
      }
      if (this.dataALLlistgs.GoodsDetails.Inventory === '') {
        uni.showToast({
          title: '请输入库存数量',
          duration: 3000,
          icon: 'none',
        })
        return
      }
      if (this.dataALLlistgs.GoodsDetails.Inventory === '0') {
        uni.showToast({
          title: '库存数量不能为0',
          duration: 3000,
          icon: 'none',
        })
        return
      }
      if (
        !/^[0-9]*[1-9][0-9]*$/.test(this.dataALLlistgs.GoodsDetails.Inventory)
      ) {
        uni.showToast({
          title: '库存数量不能小于0',
          duration: 3000,
          icon: 'none',
        })
        this.dataALLlistgs.GoodsDetails.Inventory = ''
        return
      }
      // 选择了商户端
      if (this.checked0 === true) {
        if (this.dataALLlistgs.GoodsDetails.Bus_Price === '') {
          uni.showToast({
            title: '请输入商家端渠道销售价格',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        let bussbaozhenj = Number(this.dataALLlistgs.GoodsDetails.Earnest_Money)
        if (bussbaozhenj < 800) {
          uni.showToast({
            title: '商家端保证金不能低于800元',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.Production === '') {
          uni.showToast({
            title: '请选择商家端生产日期',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.vehicleCertificate === null) {
          uni.showToast({
            title: '请选择商家端合格证',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.vehicleDetails === null) {
          uni.showToast({
            title: '请选择商家端车辆详情',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.vehicleAddrName === '') {
          uni.showToast({
            title: '请选择商家端车辆所在地',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.salesAreaName === '') {
          uni.showToast({
            title: '请选择商家端销售区域',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        if (this.vehicleStatus === null) {
          uni.showToast({
            title: '请选择商家端车辆状态',
            duration: 3000,
            icon: 'none',
          })
          return
        }
      }
      // 选择了客户端
      if (this.checked1 === true) {
        if (this.dataALLlistgs.GoodsDetails.Client_price === '') {
          uni.showToast({
            title: '请输入消费端裸车价',
            duration: 3000,
            icon: 'none',
          })
          return
        }
        //全款/按揭（0关，1开
        if (this.isLoans === 0) {
          if (
            this.financialSolution.fsid === '' &&
            this.yzdsclicklist.yzdsid === ''
          ) {
            uni.showToast({
              title: '请选择一种金融方案',
              duration: 3000,
              icon: 'none',
            })
            return
          }
          // 低首付
          if (this.financialSolution.fsid !== '') {
            let baozhenj = Number(
              this.dataALLlistgs.GoodsDetails.Down_Payment_Money
            )
            if (baozhenj < 800) {
              uni.showToast({
                title: '消费端低首付保证金不能低于800元',
                duration: 3000,
                icon: 'none',
              })
              return
            }
          }
          // 以租代售
          if (this.rentForSale) {
            if (this.yzdsclicklist.yzdsid === '') {
              uni.showToast({
                title: '请选择一种金融方案',
                duration: 3000,
                icon: 'none',
              })
              return
            }
          }
          // 以租代售
          if (this.rentForSale) {
            let baozhenj = Number(
              this.dataALLlistgs.GoodsDetails.Rent_Out_Money
            )
            if (baozhenj < 800) {
              uni.showToast({
                title: '消费端以租代售保证金不能低于800元',
                duration: 3000,
                icon: 'none',
              })
              return
            }
          }
        }
      }
      this.ReleaseCarSource()
    },

    //发布
    async ReleaseCarSource() {
      if (this.subfalse) {
        return false
      }
      this.subfalse = true
      try {
        var lpdnumber = 0
        var rfsnumber = 0
        if (this.dataALLlistgs.GoodsDetails.Down_Payment_Money === '') {
          lpdnumber = 0 //低首付
        } else {
          lpdnumber = this.dataALLlistgs.GoodsDetails.Down_Payment_Money
        }
        if (this.dataALLlistgs.GoodsDetails.Rent_Out_Money === '') {
          rfsnumber = 0 //以租代售
        } else {
          rfsnumber = this.dataALLlistgs.GoodsDetails.Rent_Out_Money
        }
        let data = {
          MyProperty: this.selecPort, //商品类型（0商户端，1客户端，2商户端客户端）
          GoodsDetails: {
            Store_Id: this.$store.state.userInfoDetail.store.storeId, //店铺id
            Valid_Time: this.bussvalidPeriod, //车源有效时间（长期为2999年1月1日）
            Factory_Price: Number(
              this.specifAll.Configulist.factoryprice.substr(
                0,
                this.specifAll.Configulist.factoryprice.search(/万/)
              )
            ), //bussGuidePrice官方指导价
            Bus_Price: this.dataALLlistgs.GoodsDetails.Bus_Price, //clickGuidePrice客户端渠道销售价格
            Client_price: this.dataALLlistgs.GoodsDetails.Client_price, //bareCarPrice客户端裸车价

            Is_loans: this.isLoans, //全款/按揭（0关，1开（开了后没有低首付和以租代售））

            Down_Payment_Id: this.financialSolution.fsid, //低首付金融方案id
            Down_Payment_Money: lpdnumber, //低首付保证金

            Rent_Out_Id: this.yzdsclicklist.yzdsid, //以租代售金融方案id
            Rent_Out_Money: rfsnumber, //以租代售保证金

            Specification: this.specifAll.Speciflist.id, //规格（0国产，1美规，2中东，3加版，4欧版，5墨西哥版）
            Brand_Id: this.specifAll.brandlist.bid, //品牌id
            Brand_Name: this.specifAll.brandlist.brand, //品牌名称
            Car_Type_Id: this.specifAll.Serieslist.carTypeId, //车辆型号id
            Car_Type_Nmae: this.specifAll.Serieslist.carTypeName, //车辆型号名称
            Configuration_Id: this.specifAll.Configulist.id, //车子配置id
            Configuration_Name: this.specifAll.Configulist.name, //车子配置名称
            Inventory: this.dataALLlistgs.GoodsDetails.Inventory, //this.inStockS, //库存数量
            Earnest_Money: this.dataALLlistgs.GoodsDetails.Earnest_Money, //bussMargin保证金
            Produced_Date: this.Production, //生产日期
            Conformity_Certificate: this.vehicleCertificate, //车辆合格证（0随车，1邮寄）
            Cardetail_Type: this.vehicleDetails, //车辆情况 0现车现票/不店保，1现车现票/店保，2质损车源，3期货/店保，4其他
            Car_Status: this.vehicleStatus, //车辆状态（0现货，1在途）
            Car_Location_Id: this.vehicleLocation, //车俩所在地id(为最小地区id)
            Car_Location_Name: this.vehicleAddrName, //车辆所在地区名称
            Sales_Territory_Id: this.salesAreaId, //销售区域id(为最小地区id)
            Sales_Territory_Name: this.salesAreaName, //销售区域名称
            Bus_Remarks: this.reason, //商户端备注
          },
          ColourList: this.xedColorList,
          ImgList: this.outsideimgwg,
        }
        const res = await this.$api.carSource.ReleaseCarSource(data)
        if (res.code === 200) {
          this.subfalse = false
          uni.$off('specifAll')
          uni.$off('carImageS')
          uni.$off('carSourceColor')
          uni.redirectTo({
            url: '/pages_common/releaseSuccess/releaseSuccess?type=117',
          })
        }
      } catch (err) {
        console.log(err)
      }
    },
    onUnload() {
      uni.$off('specifAll')
    },
    //发布成功弹框
    open() {
      // this.show = true
    },
    //查看详情
    btnlickxqy() {
      uni.redirectTo({
        url: '/pages_carSource/managementOptions/managementOptions',
      })
    },
    //清空
    jixuabu() {
      this.show = false
    },

    //确认修改
    finishedediting() {
      this.UpdateCarSource()
    },
    //删除车源
    Cancelinquiry() {
      this.showxj = true
    },
    //删除车源-我在想想
    woxiangx() {
      this.showxj = false
    },
    //确认删除车源
    requerqx() {
      this.UpdateMyCarSourceShelves(1)
    },
    //编辑车源
    async UpdateCarSource() {
      try {
        let data = {
          id: this.goodsid,
          MyProperty: this.selecPort, //商品类型（0商户端，1客户端，2商户端客户端）
          GoodsDetails: {
            Store_Id: this.$store.state.userInfoDetail.store.storeId, //店铺id
            Valid_Time: this.bussvalidPeriod, //车源有效时间（长期为2999年1月1日）
            Factory_Price: Number(
              this.specifAll.Configulist.factoryprice.substr(
                0,
                this.specifAll.Configulist.factoryprice.search(/万/)
              )
            ), //bussGuidePrice官方指导价
            Bus_Price: this.dataALLlistgs.GoodsDetails.Bus_Price, //clickGuidePrice客户端渠道销售价格
            Client_price: this.dataALLlistgs.GoodsDetails.Client_price, //bareCarPrice客户端裸车价

            Is_loans: this.isLoans, //全款/按揭（0关，1开（开了后没有低首付和以租代售））

            Down_Payment_Id: this.financialSolution.fsid, //低首付金融方案id
            Down_Payment_Money: this.dataALLlistgs.GoodsDetails
              .Down_Payment_Money, //低首付保证金

            Rent_Out_Id: this.yzdsclicklist.yzdsid, //以租代售金融方案id
            Rent_Out_Money: this.dataALLlistgs.GoodsDetails.Rent_Out_Money, //以租代售保证金

            Specification: this.specifAll.Speciflist.id, //规格（0国产，1美规，2中东，3加版，4欧版，5墨西哥版）
            Brand_Id: this.specifAll.brandlist.bid, //品牌id
            Brand_Name: this.specifAll.brandlist.brand, //品牌名称
            Car_Type_Id: this.specifAll.Serieslist.carTypeId, //车辆型号id
            Car_Type_Nmae: this.specifAll.Serieslist.carTypeName, //车辆型号名称
            Configuration_Id: this.specifAll.Configulist.id, //车子配置id
            Configuration_Name: this.specifAll.Configulist.name, //车子配置名称
            Inventory: this.dataALLlistgs.GoodsDetails.Inventory, //this.inStockS, //库存数量
            Earnest_Money: this.dataALLlistgs.GoodsDetails.Earnest_Money, //bussMargin保证金
            Produced_Date: this.Production, //生产日期
            Conformity_Certificate: this.vehicleCertificate, //车辆合格证（0随车，1邮寄）
            Cardetail_Type: this.vehicleDetails, //车辆情况 0现车现票/不店保，1现车现票/店保，2质损车源，3期货/店保，4其他
            Car_Status: this.vehicleStatus, //车辆状态（0现货，1在途）
            Car_Location_Id: this.vehicleLocation, //车俩所在地id(为最小地区id)
            Car_Location_Name: this.vehicleAddrName, //车辆所在地区名称
            Sales_Territory_Id: this.salesAreaId, //销售区域id(为最小地区id)
            Sales_Territory_Name: this.salesAreaName, //销售区域名称
            Bus_Remarks: this.reason, //商户端备注
          },
          ColourList: this.xedColorList,
          ImgList: this.outsideimgwg,
        }
        const res = await this.$api.carSource.UpdateCarSource(data)
        if (res.code === 200) {
          setTimeout(function() {
            uni.showToast({
              title: '完成修改',
              duration: 2000,
              icon: 'none',
            })
          }, 100)
          uni.navigateBack({
            delta: 1,
          })
        }
      } catch (err) {
        console.log(err)
      }
    },
    // 编辑——下架
    xiajiaClick() {
      this.showXiajia = true
    },
    // 编辑——确认下架
    footerBtn() {
      this.UpdateMyCarSourceShelves(0)
      this.showXiajia = false
    },
    // 编辑——上架
    shagnjiaClick() {
      this.showsjrqS = true
    },
    //  编辑——长期有效时间
    valclickSJ(index) {
      this.changqili.forEach((item, i) => {
        item.check = item.check === false ? true : false
      })
      if (index === 0) {
        this.validPeriodS = '2029-1-1'
        this.showsjrq = false
      }
    },
    // 编辑——商户端有效期
    sjvalidPeriodClick(e) {
      this.ProductionS = ''
      if (this.modescS === 'time') {
        if (this.paramsscS.year) this.ProductionS += e.year
        if (this.paramsscS.month) this.ProductionS += '-' + e.month
        if (this.paramsscS.day) this.ProductionS += '-' + e.day
        if (this.paramsscS.hour) this.ProductionS += ' ' + e.day
        if (this.paramsscS.minute) this.ProductionS += ':' + e.minute
        if (this.paramsscS.second) this.ProductionS += ':' + e.second
      } else {
        this.ProductionS = e.year + '-' + e.month + '-' + e.day
      }
      this.showsjrqS = false
      // 编辑——车源上架时间  长期有效2029-1-1
      if (this.validPeriodS === '2029-1-1') {
        this.UpdateMyCarSourceUpload()
        return false
      } else {
        this.validPeriodS = this.ProductionS
      }
      this.UpdateMyCarSourceUpload()
    },
    //  编辑——下架接口
    async UpdateMyCarSourceShelves(types) {
      try {
        let data = {
          Type: types, //0下架，1删除
          Id: [this.goodsid],
        }
        const res = await this.$api.carSource.UpdateMyCarSourceShelves(data)
        console.log(res)
        if (res.code === 200) {
          if (types === 0) {
            this.$refs.uToast.show({
              title: '下架成功',
              type: 'success',
              url: '/pages/user/index',
            })

            setTimeout(function() {
              uni.navigateBack()
              // uni.redirectTo({
              //   url: '/pages_carSource/managementOptions/managementOptions',
              // })
            }, 1000)
          } else {
            this.$refs.uToast.show({
              title: '删除成功',
              type: 'success',
              url: '/pages/user/index',
            })
            setTimeout(function() {
              uni.navigateBack()
              // uni.redirectTo({
              //   url: '/pages_carSource/managementOptions/managementOptions',
              // })
            }, 1000)
          }
        }
      } catch (err) {
        console.log(err)
      }
    },
    //  编辑——上架接口
    async UpdateMyCarSourceUpload() {
      try {
        let data = {
          Id: this.goodsid,
          Valid_Time: this.validPeriodS,
        }
        const res = await this.$api.carSource.UpdateMyCarSourceUpload(data)
        console.log(res)
        if (res.code === 200) {
          this.$refs.uToast.show({
            title: '上架成功',
            type: 'success',
            url: '/pages/user/index',
          })

          setTimeout(function() {
            uni.navigateBack()
            // uni.navigateTo({
            //   url: '/pages_carSource/managementOptions/managementOptions',
            // })
          }, 1000)
        }
      } catch (err) {
        console.log(err)
      }
    },
  },
}
